<template>
  <div class="recpie-recommend-item" v-if="item" @click.stop="toDetail">
    <div class="left img-box" :style="{backgroundImage:`url(${item.img})`}">
    </div>
    <div class="right">
      <div
        class="my-text title"
        v-for="(text, index) in item?.n?.split('#')?.filter(text=>text!='')?.slice(0,2)"
        :key="index"
      >
        <span v-if="text">#</span>{{ text }}
      </div>
      <div class="heat">
        <span>{{ score }}分</span><span>{{ item.recommend_label }}</span>
      </div>
      <div class="author">
        <div class="img-box">
          <img :src="item?.a?.p" alt="">
        </div>
        <div class="name">{{item.a.n}}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["item"],
  computed: {
    score() {
      let score = Math.floor(Math.random() * 3) + 3;
      if (score < 5) {
        score += Math.random() < 0.5 ? 0 : 0.5;
      }
      return score;
    },
  },
  methods:{
    toDetail(){
      this.$router.push({
        name:"fooddetail",
        params:{
          foodid:this.item.id
        }
      })
    }
  },
  created() {
    console.log(this.item);
  },
};
</script>

<style lang="scss" scoped>
.recpie-recommend-item {
  width: 100%;
  display: flex;
  margin-bottom: 0.1rem;
  color: var(--text-black);
  .left {
    width: 1.7rem;
    min-width: 1.7rem;
    height: 1.2rem;
    border-radius: 0.1rem;
    overflow: hidden;
  }
  .right {
    position: relative;
    margin-left: 0.1rem;
    padding: 0.05rem 0;
    .title {
      font-size: 0.15rem;
      line-height: 0.18rem;
      -webkit-line-clamp: 2;
    }
    .heat {
      font-size: 0.12rem;
      >span{
        margin-right: 0.05rem;
      }
    }
    .author{
      position: absolute;
      left: 0;
      bottom: 0.05rem;
      width: 100%;
      display: flex;
      align-items: center;
      font-size: 0.12rem;
      color: var(--text-gray);
      .img-box{
        width: 0.18rem;
        min-width: 0.18rem;
        height: 0.18rem;
        border-radius: 50%;
        overflow: hidden;
        margin-right: 0.1rem;
      }
    }
  }
}
</style>